#include<iostream>
#include<string.h>
#define MaxSize 500
using namespace std;
typedef char ElementType;
typedef int Position;
typedef struct SNode {
    ElementType Data;
    struct SNode *next; 
}Stack;

void InitStack(Stack *&s);
void DestoryStack(Stack *&s);
bool StackEmpty(Stack *s);
void Push(Stack *&s,ElementType e);
bool Pop(Stack *&s,ElementType &e);
bool GetTop(Stack *s,ElementType &e);
bool Match(Stack *s,ElementType exp[],int n); 
int main()
{
	Stack *s;
	ElementType e[MaxSize]="\0",e1[MaxSize];
	int i=0;
	InitStack(s);
	while(true){
		gets(e1);
		if(e1[0]=='.')break;
		strcat(e,e1);
	}
	i=strlen(e);
	Match(s,e,i);
	DestoryStack(s);
}
void InitStack(Stack *&s){
    s=new Stack;
	s->next=NULL;
}
void DestoryStack(Stack *&s){
	Stack *p=s,*q=s->next;
	while(q!=NULL){
		delete p;
		p=q;
		q=p->next;
	}
	delete p;
}
bool StackEmpty(Stack *s){
	return (s->next==NULL);
}
void Push(Stack *&s,ElementType e){ 
    Stack* p;
    p=new Stack;
    p->Data=e;
    p->next=s->next;
	s->next=p; 
}

bool Pop(Stack *&s,ElementType &e){
	Stack *p;
	if(s->next==NULL)return false;
	p=s->next;
	e=p->Data;
	s->next=p->next;
	delete p;
	return true; 
}
bool GetTop(Stack *s,ElementType &e){
	if(s->next==NULL)return false;
	e=s->next->Data;
	return true;
}
bool Match(Stack *s,ElementType exp[],int n){
	int i=0,j=0;ElementType e;
	ElementType m,ch;
	bool flag=true;
	while(i<n&&flag){	
		if(exp[i]=='('||exp[i]=='{'||exp[i]=='[')
			Push(s,exp[i]);
		else if(exp[i]=='/'&&exp[i+1]=='*')
			Push(s,exp[i]),i++;
		else if((exp[i]=='*'&&exp[i+1]=='/')){
			if(GetTop(s,e)==true){
				if(e!='/'){
					m='d';flag=false;break;
				}
				else Pop(s,e);
			}
			else {
				m='d';flag=false;break;
			}i++; 
		}
				
		else if(exp[i]==')'){
			if(GetTop(s,e)==true){
				if(e=='(')Pop(s,e);
				else {
					m='a';flag=false;break;
				}
			}
			else {
				m='a';flag=false;break;
			}
		}
				
		else if(exp[i]=='}'){
			if(GetTop(s,e)==true){
				if(e!='{'){
					m='b';flag=false;break;
				}
				else Pop(s,e);
			}
			else {
				m='b';flag=false;break;
			}
		}
				
		else if(exp[i]==']'){
			if(GetTop(s,e)==true){
				if(e!='['){
					m='c';flag=false;break;
				}
				else Pop(s,e);
			}
			else{
				m='c';flag=false;break;
			} 
		}
		i++;
	}
	if(!StackEmpty(s))
		flag=false;
	if(flag){
		cout<<"YES";return true;
	}
	else {
		cout<<"NO"<<endl; 
		if(GetTop(s,ch)==true){
			if(ch=='(')cout<<'(';
			else if(ch=='[')cout<<'[';
			else if(ch=='{')cout<<'{';
			else if(ch=='/')cout<<"/*";
			cout<<"-?";
		}
		else {
			cout<<"?-";
			if(m=='a')cout<<')';
			else if(m=='b')cout<<'}';
			else if(m=='c')cout<<']';
			else if(m=='d')cout<<"*/";
		}
		return false;	
	}
}

